/*
 * Author  : Mani Shankar Pampana V
 * Email   : manishankar.pv@gmail.com
 * Licence : GPLv2 or Above
 * File    : yacc.y
 *
 * Unfortunately this code is not 
 * commented Doxygen friendly :P
 */

%{
#include <stdio.h>
%}

%token EOP IDENTIFIER NUMBER OPERATION DEREF ARRAY DARRAY IARRAY

%%
source:statement
      | statement '\n'
      | '\n'
      ;

statement: expression EOP
         | IDENTIFIER '=' expression EOP  {printf("%s\n",$$);}
         | IDENTIFIER '[' NUMBER ']' '=' expression EOP  {printf("%s\n",$$);}
         | IDENTIFIER '[' IDENTIFIER ']' '=' expression EOP  {printf("%s\n",$$);}
         | DEREF '=' expression EOP  {printf("%s\n",$$);}
         | ARRAY '=' expression EOP  {printf("%s\n",$$);}
         | DARRAY '=' expression EOP  {printf("%s\n",$$);}
         | IARRAY '=' expression EOP  {printf("%s\n",$$);}
         ;

expression: NUMBER
          | IDENTIFIER
          | ARRAY
          | IARRAY
          | DEREF
          | fcall
          | expression OPERATION expression
          | '(' expression ')'
          ;

fcall: fcall '.' fcall '(' ')'
     | fcall "->" fcall '(' ')'
     | fcall '.' fcall
     | fcall "->" fcall
     | IDENTIFIER '(' ')'
     | IDENTIFIER
     | DEREF
     | DEREF '(' ')'
     ;
//pattern: IDENTIFIER EOP {printf("/* \n * Doxygen Friendly?\n */\n%s\n\n",$$);};*/

%%
extern FILE *yyin;
main(){
   do {
      yyparse();
   }
   while(!feof(yyin));
}
yyerror(char *s)
{
   fprintf(stderr, "%s\n",s);
}